<?php

namespace app\api\controller;

use addons\wechat\library\Config as ConfigService;
use app\api\model\OrderGoods;
use app\api\model\ShopGoods;
use app\api\model\UserAddress;
use app\common\controller\Api;
use app\common\library\Tools;
use EasyWeChat\Foundation\Application;
use EasyWeChat\Payment\Order as WxOrder;
use think\Db;
use think\Log;
use think\Model;
use think\Request;
use think\Validate;

/**
 * F-订单相关接口
 * @ApiWeigh    (96)
 */
class Order extends Api {
	protected $noNeedLogin = [''];
	protected $noNeedRight = ['*'];

//	protected $shopGoodsModel = null;
//	protected $userAddressModel = null;
//	protected $shopOrderModel = null;
//	protected $shopOrderGoodsModel = null;
//	protected $cartModel = null;
//
//	public function __construct( Request $request = null ) {
//		parent::__construct( $request );
//
//		$this->shopGoodsModel      = new ShopGoods();
//		$this->userAddressModel    = new UserAddress();
//		$this->shopOrderModel      = new \app\api\model\Order();
//		$this->shopOrderGoodsModel = new OrderGoods();
//		$this->cartModel           = new \app\api\model\Cart();
//	}

	/**
	 * 我的商品
	 *
	 * @ApiTitle    (我的商品)
	 * @ApiSummary  (我的商品)
	 * @ApiMethod   (POST)
	 * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
	 *
	 * @ApiParams   (name="status", type="integer", required=false, description="订单状态:0=全部,1=待付款,2=待发货,3=待签收,4=已完成")
	 *
	 * @ApiReturnParams   (name="total", type="object", description="订单总数")
	 * @ApiReturnParams   (name="per_page", type="object", description="每页显示数据")
	 * @ApiReturnParams   (name="current_page", type="object", description="当前页")
	 * @ApiReturnParams   (name="last_page", type="object", description="最后一页")
	 * @ApiReturnParams   (name="data", type="array", description="我的订单[]")
	 * @ApiReturnParams   (name="data.id", type="integer", description="订单id")
	 * @ApiReturnParams   (name="user_id", type="integer", description="用户id")
	 * @ApiReturnParams   (name="order_no", type="string", description="订单号")
	 * @ApiReturnParams   (name="pay_price", type="float", description="合计支付价格")
	 * @ApiReturnParams   (name="createtime", type="string", description="每个商品下单支付时间-都用这个字段")
	 * @ApiReturnParams   (name="order_status", type="float", description="订单状态:0=全部,2=待发货,3=待签收,4=已完成")
	 *
	 * @ApiReturnParams   (name="goods_detail", type="array", description="订单商品详情")
	 * @ApiReturnParams   (name="goods_detail.id", type="integer", description="订单商品id")
	 * @ApiReturnParams   (name="goods_detail.user_id", type="integer", description="用户id")
	 * @ApiReturnParams   (name="goods_detail.order_id", type="integer", description="订单id")
	 * @ApiReturnParams   (name="goods_detail.goods_id", type="integer", description="订单商品id")
	 * @ApiReturnParams   (name="goods_detail.goods_name", type="string", description="订单商品名称")
	 * @ApiReturnParams   (name="goods_detail.goods_no", type="string", description="订单商品编号")
	 * @ApiReturnParams   (name="goods_detail.goods_price", type="float", description="商品单价")
	 * @ApiReturnParams   (name="goods_detail.image", type="string", description="商品图片物理路径")
	 * @ApiReturnParams   (name="goods_detail.total_num", type="integer", description="该商品购买数量")
	 * @ApiReturnParams   (name="goods_detail.total_price", type="integer", description="该商品购买数量*商品单价=总价")
	 *
	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
	 * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
	 * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
	 * @ApiReturn   ({
	"code":"状态码",
	"msg": "提示消息",
	"data": {
	}
	})
	 */
	public function index() {
		$model  = new \app\api\model\Order();
		$userId = $this->auth->id;
		$param  = $this->request->param();
		$status=$param['status'];
		$list = $model->with( ['goods_detail'] )
			->where(function ($query) use ($status,$userId){
				if ($status == 0){
					$status = [2,3,4];
					$query->whereIn('order_status',$status)->where('order_status','<>',1)->where('user_id', $userId);
				}
				$query->where('order_status',$status)->where('order_status','<>',1)->where('user_id', $userId);
			})
			->order( 'id', 'desc' )
			->paginate()
			->toArray();
		$this->success( '订单列表', $list );
	}

//	/**
//	 * @ApiTitle    (订单详情)
//	 * @ApiSummary  (订单详情)
//	 * @ApiMethod (POST)
//	 * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
//	 * @ApiParams   (name="id", type="integer", required=true, description="订单ID")
//	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
//	 * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
//	 * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
//	 * @ApiReturn   ({
//	"code":"状态码",
//	"msg": "提示消息",
//	"data": {
//
//	}
//	})
//	 */
//	public function detail() {
//		$rules    = [
//			'id' => 'require',
//		];
//		$message  = [
//			'id.require' => '订单不能为空',
//		];
//		$validate = new Validate( $rules, $message );
//
//		$param = $this->request->param();
//		if ( !$validate->check( $param ) ) {
//			$this->error( $validate->getError() );
//		}
//		$model = new \app\api\model\Order();
//		$info  = $model->with( ['goods_detail'] )->where( ['id' => $param['id']] )->find();
//		$this->success( '修改成功', $info );
//
//	}
//
//	/**
//	 * @ApiTitle    (取消订单)
//	 * @ApiSummary  (取消订单)
//	 * @ApiMethod (POST)
//	 * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
//	 * @ApiParams   (name=id, type=integer, required=true, description="订单ID")
//	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
//	 * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
//	 * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
//	 * @ApiReturn   ({
//	"code":"状态码",
//	"msg": "提示消息"
//	})
//	 */
//	public function cancel() {
//		$rules    = [
//			'id' => 'require',
//		];
//		$message  = [
//			'id.require' => '请选择订单',
//		];
//		$validate = new Validate( $rules, $message );
//
//		$param = $this->request->param();
//		if ( !$validate->check( $param ) ) {
//			$this->error( $validate->getError() );
//		}
//		$model = new \app\api\model\Order();
//		$row   = $model->cancel( $param['id'] );
//
//		if ( $row ) {
//			$this->success( '取消成功' );
//		} else {
//			$this->error( '取消失败' );
//		}
//	}

	/**
	 * 确认收货
	 *
	 * @ApiTitle    (确认收货)
	 * @ApiSummary  (确认收货)
	 * @ApiMethod   (POST)
	 * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
	 *
	 * @ApiParams   (name=id, type=integer, required=true, description="订单ID")
	 *
	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码:1=收获成功,0=收货失败")
	 * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
	 * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
	 * @ApiReturn   ({
	"code":"状态码",
	"msg": "提示消息"
	})
	 */
	public function receipt() {
		$rules    = [
			'id' => 'require',
		];
		$message  = [
			'id.require' => '请选择订单',
		];
		$validate = new Validate( $rules, $message );

		$param = $this->request->param();
		if ( !$validate->check( $param ) ) {
			$this->error( $validate->getError() );
		}
		$model = new \app\api\model\Order();
		$row   = $model->receipt( $param['id'] );
		if ( $row ) {
			$this->success( '收获成功' );
		} else {
			$this->error( '收货失败' );
		}
	}

	/**
	 * 查看物流
	 *
	 * @ApiTitle    (查看物流)
	 * @ApiSummary  (根据订单id查询该订单的物流信息)
	 * @ApiMethod   (POST)
	 * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
	 *
	 * @ApiParams   (name=id, type=integer, required=true, description="订单ID")
	 *
	 * @ApiReturnParams   (name="express_company", type="string", required=true, description="物流公司")
	 * @ApiReturnParams   (name="express_no", type="string", required=true, description="物流单号")
	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码:1=查看成功,0=查看失败")
	 * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
	 * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
	 * @ApiReturn   ({
	"code":"状态码",
	"msg": "提示消息"
	})
	 */
	public function material_flow() {
		$rules    = [
			'id' => 'require',
		];
		$message  = [
			'id.require' => '请选择订单',
		];
		$validate = new Validate( $rules, $message );

		$param = $this->request->param();
		if ( !$validate->check( $param ) ) {
			$this->error( $validate->getError() );
		}
		$model    = new \app\api\model\Order();
		$field    = 'express_company,express_no';
		$liu_info = $model->where( 'id', $param['id'] )->field( $field )->find();
		$this->success( '物流信息展示', $liu_info );
	}

//	/**
//	 * @ApiTitle    (申请售后)
//	 * @ApiSummary  (申请售后)
//	 * @ApiMethod (POST)
//	 * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
//	 * @ApiParams   (name=id, type=integer, required=true, description="订单ID")
//	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
//	 * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
//	 * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
//	 * @ApiReturn   ({
//	"code":"状态码",
//	"msg": "提示消息"
//	})
//	 */
//	public function refund() {
//		$rules    = [
//			'id' => 'require',
//		];
//		$message  = [
//			'id.require' => '请选择订单',
//		];
//		$validate = new Validate( $rules, $message );
//
//		$param = $this->request->param();
//		if ( !$validate->check( $param ) ) {
//			$this->error( $validate->getError() );
//		}
//		$model = new \app\api\model\Order();
//		$info  = $model->where( ['id' => $param['id'], 'order_status' => ['in', '2,3']] )->find();
//		if ( empty( $info ) ) {
//			$this->error( '非可退款订单' );
//		}
//		if ( $info['refund_status'] == 2 ) {
//			$this->error( '你得退款申请被拒绝' );
//		}
//		$row = $model->save( ['order_status' => 21, 'receipt_time' => time()], ['id' => $param['id'], 'order_status' => ['in', '2,3']] );
//		if ( $row ) {
//			$this->success( '申请成功' );
//		} else {
//			$this->error( '申请失败' );
//		}
//	}
//
//	/**
//	 * @ApiTitle    (订单支付)
//	 * @ApiSummary  (订单支付)
//	 * @ApiMethod   (POST)
//	 * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
//	 * @ApiParams   (name="id", type="string", required=true, description="订单ID")
//	 * @ApiParams   (name="openid", type="string", required=true, description="OPENID")
//	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
//	 * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
//	 * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
//	 * @ApiReturn   ({
//	"code":"状态码",
//	"msg": "提示消息"
//	})
//	 */
//	public function pay() {
//		$openid = $this->request->param( 'openid' );
//		$id     = $this->request->param( 'id' );
//		if ( empty( $id ) ) {
//			$this->error( '请选择订单' );
//		}
//		$model = new \app\api\model\Order();
//		$row   = $model->where( ['id' => $id] )->find();
//		if ( empty( $row ) ) {
//			$this->error( '订单不存在' );
//		}
//		if ( $row['order_status'] != 1 ) {
//			$this->error( '订单状态错误' );
//		}
//		$userId  = $this->auth->id;
//		$orderNo = get_order_sn( 'D' );
//		$row->save( ['pay_order_no' => $orderNo] );
//		//todo 虚拟金额
//		//$row['pay_price']=0.01;
//		$openid     = !empty( $openid ) ? $openid : Db::name( 'third' )->where( ['user_id' => $userId] )->value( 'openid' );
//		$attributes = [
//			'trade_type'   => 'JSAPI',
//			'body'         => '订单支付',
//			'detail'       => '订单支付',
//			'out_trade_no' => $orderNo,
//			'total_fee'    => $row['pay_price'] * 100, // 单位：分
//			'notify_url'   => url( 'order/notify', [], true, true ),
//			'openid'       => $openid,
//		];
//
//		$order   = new WxOrder( $attributes );
//		$app     = new Application( ConfigService::load() );
//		$payment = $app->payment;
//		$result  = $payment->prepare( $order );
//		if ( $result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS' ) {
//			$prepayId        = $result->prepay_id;
//			$jsApiParameters = $payment->configForJSSDKPayment( $prepayId );
//			Db::commit();
//			$this->success( '', ['jsApiParameters' => $jsApiParameters, 'id' => $id] );
//		} else {
//			$this->error( '支付参数错误', $result );
//		}
//	}
//
//	/**
//	 * @ApiTitle    (订单支付回调)
//	 * @ApiInternal
//	 */
//	public function notify() {
//		$app      = new Application( ConfigService::load() );
//		$response = $app->payment->handleNotify( function ( $notify, $successful ) {
//			// 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
//			$out_trade_no = $notify->out_trade_no;
//			$info         = Db::name( 'shop_order' )->where( ['pay_order_no' => $out_trade_no] )->find();
//			if ( !$info ) { // 如果订单不存在
//				return 'Order not exist.'; // 告诉微信，我已经处理完了，订单没找到，别再通知我了
//			}
//			// 如果订单存在
//			// 检查订单是否已经更新过支付状态
//			if ( $info['order_status'] > 1 ) {
//				return true; // 已经支付成功了就不再更新了
//			}
//			// 用户是否支付成功
//			if ( $successful ) {
//				$time                     = time();
//				$update['transaction_id'] = $notify->transaction_id;// 回填微信的订单号
//				$update['pay_time']       = $time;
//				// 不是已经支付状态则修改为已经支付状态
//				$update['order_status'] = 2;
//				Db::name( 'shop_order' )->where( ['id' => $info['id']] )->update( $update );
//				$goodsList = collection( ( new OrderGoods() )->where( ['order_id' => $info['id']] )->select() )->toArray();
//				$model     = new \app\api\model\Goods();
//				$model->updateStockSales( $goodsList );
//				Log::write( '支付回调数据' );
//				Log::write( $notify );
//				return true; // 返回处理完成
//			} else { // 用户支付失败
//				return false; // 返回处理完成
//			}
//		} );
//
//		$response->send();
//	}

//	/**
//	 * 自己写的废弃-立即购买-下单页
//	 *
//	 * @ApiTitle    (立即购买-下单页)
//	 * @ApiSummary  (点击商品详情页中【立即购买】按钮获取用户默认收货地址&下单商品信息)
//	 * @ApiMethod   (POST/GET)
//	 *
//	 * @ApiParams   (name="goods_id", type="integer", required=true, description="商品id")
//	 *
//	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
//	 * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
//	 * @ApiReturnParams   (name="data", type="object", description="返回数据")
//	 * @ApiReturnParams   (name="goods_info", type="object", description="商品信息")
//	 * @ApiReturnParams   (name="goods_info.id", type="object", description="商品id")
//	 * @ApiReturnParams   (name="goods_info.name", type="object", description="商品名称")
//	 * @ApiReturnParams   (name="goods_info.goods_no", type="object", description="商品编号")
//	 * @ApiReturnParams   (name="goods_info.category_id", type="object", description="商品类别")
//	 * @ApiReturnParams   (name="goods_info.image", type="object", description="商品缩略图物理地址")
//	 * @ApiReturnParams   (name="goods_info.goods_price", type="object", description="商品价格")
//	 * @ApiReturnParams   (name="goods_info.stock_num", type="object", description="商品库存")
//	 * @ApiReturnParams   (name="address_info", type="object", description="地址信息")
//	 * @ApiReturnParams   (name="address_info.id", type="integer", description="地址id")
//	 * @ApiReturnParams   (name="address_info.name", type="string", description="收件人")
//	 * @ApiReturnParams   (name="address_info.mobile", type="string", description="电话号码")
//	 * @ApiReturnParams   (name="address_info.address_now", type="string", description="所在地区")
//	 * @ApiReturnParams   (name="address_info.address", type="string", description="详细地址")
//	 */
//	public function buy_now_page() {
//		//获取参数
//		$params = $this->request->param();
//		//验证参数
//		$validate = $this->validate( $params, [
//			'goods_id|商品ID' => 'require|number',
//		] );
//
//		if ( $validate !== true ) {
//			$this->error( $validate );
//		}
//		$goods_id      = $params['goods_id'];
//		$num           = $params['num'];
//		$login_user_id = $this->auth->id;
//
//		//查询商品详情
//		$goods_field         = 'id,name,goods_no,category_id,image,goods_price,stock_num';
//		$goods_info          = $this->shopGoodsModel->field( $goods_field )->where( 'id', $goods_id )->find();
//		$goods_info['image'] = cdnurl( $goods_info['image'], true );
//		//查询用户设置的默认地址（优先）,没有设置默认地址返回已有的、创建时间倒序的(视为最近新建的地址)设置地址
//		$where = [
//			'user_id'    => $login_user_id,
//			'is_default' => 1
//		];
//		$field = 'id,name,mobile,address,address_now';
//
//		$default_address_info = $this->userAddressModel->field( $field )->where( $where )->find();
//		//手机号*****
//		$default_address_info['mobile'] = substr( $default_address_info['mobile'], 0, 3 ) . '****' . substr( $default_address_info['mobile'], 7 );
//		if ( $default_address_info ) {
//			$this->success( '商品信息+地址信息', ['goods_info' => $goods_info, 'address_info' => $default_address_info] );
//		} else {
//			$address_info = $this->userAddressModel->field( $field )->where( 'user_id', $login_user_id )->order( ['createtime' => 'desc'] )->find();
//			$this->success( '商品信息+地址信息', ['goods_info' => $goods_info, 'address_info' => $address_info] );
//		}
//	}

//	/**
//	 * 自己写的废弃-立即购买-确认订单+微信支付
//	 *
//	 * @ApiTitle    (立即购买-确认订单+微信支付)
//	 * @ApiSummary  (点击下单页中确认订单按钮唤起微信支付付款操作)
//	 * @ApiMethod   (POST/GET)
//	 *
//	 * @ApiParams   (name="goods_id", type="integer", required=true, description="商品id")
//	 * @ApiParams   (name="address_id", type="integer", required=true, description="用户收货地址id")
//	 * @ApiParams   (name="total_num", type="integer", required=true, description="购买数量")
//	 * @ApiParams   (name="pay_price", type="float", required=true, description="订单合计金额")
//	 * @ApiParams   (name="open_id", type="string", required=true, description="用户openId-通过A登录相关接口获取")
//	 *
//	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
//	 */
//	public function buy_now() {
//		//获取参数
//		$params = $this->request->param();
//		//验证参数
//		$validate = $this->validate( $params, [
//			'goods_id|商品ID'       => 'require|number',
//			'address_id|用户收货地址id' => 'require|number',
//			'total_num|购买数量'      => 'require|number',
//			'pay_price|订单合计金额'    => 'require',
//			'open_id|用户openId'    => 'require',
//		] );
//
//		if ( $validate !== true ) {
//			$this->error( $validate );
//		}
//
//		$login_user_id = $this->auth->id;
//		$goods_id      = $params['goods_id'];
//		$address_id    = $params['address_id'];
//		$pay_price     = $params['pay_price'];
//		$total_num     = $params['total_num'];
//		$open_id       = $params['open_id'];
//
//		//查询商品信息
//		$goods_info = $this->shopGoodsModel->where( 'id', $goods_id )->find();
//		//查询收货地址信息
//		$address_info = $this->userAddressModel->where( 'id', $address_id )->find();
//		//保存-订单数据
//		$time       = time();
//		$order_data = [
//			'user_id'      => $login_user_id,
//			'order_no'     => Tools::getOrderNo( $login_user_id ),
//			'total_price'  => $goods_info['goods_price'],//商品金额-单价
//			'pay_price'    => $pay_price,
//			'sh_mobile'    => $address_info['mobile'],
//			'sh_name'      => $address_info['name'],
//			'sh_address'   => $address_info['address_now'] . '-' . $address_info['address'],
//			'pay_time'     => $time,//支付时间
//			'order_status' => 1,//待支付
//			'pay_type'     => 1,//
//			'createtime'   => $time
//		];
//		$order_id   = $this->shopOrderModel->insertGetId( $order_data );
//		//保存-订单商品数据
//		$address_data = [
//			'user_id'     => $login_user_id,
//			'order_id'    => $order_id,
//			'goods_id'    => $goods_id,
//			'goods_name'  => $goods_info['name'],
//			'goods_no'    => $goods_info['goods_no'],
//			'goods_price' => $goods_info['goods_price'],
//			'image'       => $goods_info['image'],
//			'total_num'   => $total_num,
//			'total_price' => $pay_price,
//		];
//		$this->shopOrderGoodsModel->save( $address_data );
//
//		//确认订单->唤起微信支付信息->返回支付信息
//		$order_info = $this->shopOrderModel->where( 'id', $order_id )->find();
//		$payservice = new \addons\epay\library\Service();
//		//提交预支付订单参数
//		$order_param = [
//			'amount'    => $order_info['pay_price'],
//			'orderid'   => $order_info['order_no'],
//			'type'      => 'wechat', //微信
//			'title'     => $goods_info['name'],
//			'notifyurl' => $this->request->domain() . '/api/notify/service/type/wechat',
//			'returnurl' => '',
//			'method'    => 'mp', //公众号
//			'openid'    => $open_id,
//		];
//		$result      = $payservice::submitOrder( $order_param );
//		$this->success( '支付信息', ['payDetail' => $result, 'order_id' => $order_info['id']] );
//	}

//	/**
//	 * 自己写的废弃-购物车-去结算下单页
//	 *
//	 * @ApiTitle    (购物车-去结算下单页)
//	 * @ApiSummary  (点击购物车中【去结算】按钮获取用户默认收货地址&下单商品信息显示)
//	 * @ApiMethod   (POST/GET)
//	 *
//	 * @ApiParams   (name="cart_ids[]", type="array", required=true, description="购物车id-传数组用英文逗号分割")
//	 *
//	 * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
//	 */
//	public function buy_cart_page() {
//		//获取前端传来的参数
//		$params = $this->request->param();
//		//验证参数
//		$validate = $this->validate( $params, [
//			'cart_ids|购物车ID' => 'require|array',
//		] );
//
//		if ( $validate !== true ) {
//			$this->error( $validate );
//		}
//
//		$cart_ids = $this->request->param( 'cart_ids/a' );
//
//		$order_total_price = 0;
//		$goodsInfoArr      = [];
//
//		//循环查询去结算的购物车商品
//		foreach ( $cart_ids as $key => $cart_id ) {
//			//查询购物车商品信息
//			$cartInfo = $this->cartModel->where( 'id', $cart_id )->find();
//
//			if ( !$cartInfo ) {
//				continue;
//			}
//
//			$goods_id    = $cartInfo['goods_id']; //商品id
//			$goods_count = $cartInfo['num']; //购物车商品数量
//
//			//查询商品详情
//			$goods_info = $this->shopGoodsModel->where( 'id', $goods_id )->find();
//			//该商品购物车总价格
//			$total_price = $goods_info['goods_price'] * $goods_count;
//
//			$goodsInfo          = [
//				'user_id'     => $this->auth->id,
//				'goods_id'    => $goods_id,
//				'goods_name'  => $goods_info['name'],
//				'goods_no'    => $goods_info['goods_no'],
//				'goods_price' => $goods_info['goods_price'],
//				'image'       => $goods_info['image'],
//				'total_num'   => $goods_count,
//				'total_price' => $total_price,
//			];
//			$goodsInfoArr[$key] = $goodsInfo;
//			//订单总价格
//			$order_total_price += $total_price;
//
//			//获取用户默认送货地址
//			$address_info = $this->userAddressModel->where( 'user_id', $this->auth->id )->where( 'is_default', 1 )->find();
//
//			try {
//				Db::startTrans();
//				$time = time();
//				//记录订单信息
//				$orderInfo = [
//					'user_id'      => $this->auth->id,
//					'order_no'     => Tools::getOrderNo( $this->auth->id ),
//					'total_price'  => $goods_info['goods_price'],//商品金额-单价
//					'pay_price'    => $order_total_price, //订单总支付金额
//					'sh_mobile'    => $address_info['mobile'],
//					'sh_name'      => $address_info['name'],
//					'sh_address'   => $address_info['address_now'] . '-' . $address_info['address'],
//					'pay_time'     => $time,//支付时间
//					'order_status' => 1,//待支付
//					'pay_type'     => 1,//
//					'createtime'   => $time
//				];
//				$order_id  = $this->shopOrderModel->insertGetId( $orderInfo );
//
//				//记录订单商品信息
//				foreach ( $goodsInfoArr as &$value ) {
//					$value['order_id'] = $order_id;
//				}
//				//记录订单商品信息
//				$this->shopOrderGoodsModel->saveAll( $goodsInfoArr );
//				//删除购物车记录
//				$this->cartModel->whereIn( 'id', $cart_ids );
//				Db::commit();
//			} catch ( \Exception $e ) {
//				Db::rollBack();
//				$this->error( $e->getMessage() );
//			}
//			//查询下单的所有订单商品信息
//			$buy_order_info = $this->shopOrderGoodsModel->where( 'order_id', $order_id )->select();
//			$this->success( 'success', ['order_id' => $order_id, 'address_info' => $address_info, 'buy_order_info' => $buy_order_info] );
//		}
//
//	}
}
